package com.example.gokuplayalong.bases.push;

import com.example.gokuplayalong.bases.beans.AppParams;
import com.example.gokuplayalong.bases.exception.ExceptionUtils;
import com.example.gokuplayalong.bases.threadpool.CustomThreadPoolExecutor;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Publish {
    static Publish INSTANCE = null;

    public static Publish getInstance() {
        if (INSTANCE == null) INSTANCE = new Publish();
        return INSTANCE;
    }

    public void pushMessageToOne(String phone, String jsonArray) {


        CustomThreadPoolExecutor.getInstance().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    OkHttpClient okHttpClient = new OkHttpClient();
                    FormBody formBody = new FormBody.Builder().add("phone", phone).add("extras", jsonArray).build();
                    Request request = new Request.Builder().url(AppParams.getInstance().baseIpPort + "/pushMessageToOne").post(formBody).build();
                    Response response = okHttpClient.newCall(request).execute();
                    if (response.isSuccessful()) {

                    }

                } catch (Throwable e) {
                    ExceptionUtils.getException(ExceptionUtils.getTraceInfo(), e);
                }
            }
        });
    }
}
